package com.ambimmort.shj.service.generalfile;

import cn.net.greenet.common.db_service.BaseDao;
import cn.net.greenet.db.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.PrintWriter;
import java.sql.ResultSet;

/**
 * Created by 师梁 on 2015/7/30.
 */

@Service("del_AppService")
public class Del_AppService {

//    @Autowired
//    private SessionFactory hibernateSessionFactory;
    ResultSet rs = null;
    BaseDao baseDao = null;
    String sql = null;

    private void init() {
        baseDao = new BaseDao();
    }

    private void close() {
        if (baseDao != null) {
            baseDao.close();
        }
    }
    public boolean del(String ids){

        String[] arr = ids.split(",");

        boolean result = false;
        init();
        try {
            for (int i = 0; i < arr.length; i++) {
                String one = arr[i];
                String[] a = one.split("_");
                if (a.length == 3) {
                    String appName = a[0];
                    String appTypeId = a[1];
                    String appID = a[2];

                   sql = "select * from Appdef as w where w.id.name=? and w.apptype.id=?";
                    Object[] params ={appName,appTypeId};
                    rs=baseDao.executeSQL(sql,params);
                }
            }
            result = true;
        } finally {
           close();
//            sf.close();
            return result;
        }
    }
//    String[] arr = ids.split(",");
//
//    boolean result = false;
//    Session session = hibernateSessionFactory.openSession();;
//    session.clear();
//    try {
//        Transaction tx = session.beginTransaction();
//        for (int i = 0; i < arr.length; i++) {
//            String one = arr[i];
//            String[] a = one.split("_");
//            if (a.length == 3) {
//                String appName = a[0];
//                String appTypeId = a[1];
//                String appID = a[2];
//                String hql = "from Appdef as w where w.id.name=? and w.apptype.id=?";
//                Query query = session.createQuery(hql);
//                query.setString(0, appName);
//                query.setInteger(1, Integer.parseInt(appTypeId));
//                query.executeUpdate();
//            }
//        }
//        result = true;
//        tx.commit();
//    } finally {
//        session.close();
////            sf.close();
//        return result;
//    }
//}
}
